<?php

	$TEMP->set_file(array('handle' => DIR_VIEW_REGISTRAR . 'activateSubjectStudent.html'));
	
	$STUDID		= _GET('studid');
	
	$getStudentInformation 		= $STUD->getStudentInformation($STUDID);
	$getFreshmenSemesterLinker 	= $DSC->getFreshmenSemesterLinker($getStudentInformation['course_idFK']);
	$stud_idPK 			= $getStudentInformation['stud_idPK'];
	$stud_no 			= $getStudentInformation['stud_no'];
	$first_name 		= $getStudentInformation['first_name'];
	$middle_name 		= $getStudentInformation['middle_name'];
	$last_name 			= $getStudentInformation['last_name'];
	$course_idFK 		= $getStudentInformation['course_idFK'];
	$course_desc 		= $getStudentInformation['course_desc'];
	$dept_desc 			= $getStudentInformation['dept_desc'];
	$course_desc 		= $getStudentInformation['course_desc'];
	
	$semAlreadyTaken 	= $STUD->getSemAlreadyTeken($STUDID, $course_idFK);
	$semTakenEnd 		= end($semAlreadyTaken);

	$semesterLabel	= $DSC->getSemesterLabel($semTakenEnd['stud_sem_active']);
	
	$activeSemesterStud = $STUD->getSemesterEnrollmentActive($STUDID);
	
	if ( isset($_POST['subButton']) ) {
		
		$if_error		= 0;
		$listsubjtaken	 	= _POST('list_subj_taken');
		
		if ( empty($listsubjtaken) ) { $if_error++; }

		if ( $if_error == 0 ) {
			$expListsubjtaken = explode(', ', $listsubjtaken);
			if ( !empty($activeSemesterStud) ) 
				$STUD->ActivateStudentSemester($activeSemesterStud['stud_sem_idPK']);
			else
				$STUD->getInsertStudSubjEnrollID($stud_idPK, $course_idFK, $activeYear, $expListsubjtaken, $active_subj_taken, $semTakenEnd['stud_sem_active']);
			redirect('?page=Students');
		}
		
	}
	else {
		$recordSaved = '0';
	}

	$semSubjList = $STUD->getStudentSubjectTakenListSeperateBySem($STUDID, $course_idFK, $activeSemesterStud['sem_linker_idFK']);

	if ( !empty($semSubjList) ) {
		$activeSubj  	= '';
		$TEMP->set_block('handle',  'subjects', 'subjectsRow');
		foreach($semSubjList as $semSubjListField => $studentSubjectList) {
			$semDesc = $DSC->getSemesterDescViaLinker($semSubjListField);
			$subjListHTML = '<span class="enrollment-label"><strong>' . $semDesc['sem_desc'] . '</span></strong>';
			if (!empty($studentSubjectList)) {
				$count = 1;
				foreach($studentSubjectList as $studentSubjectListVal) {
					$subjListHTML .= '<div class="enrollment-lock">&nbsp;<span class="numbering-previous-grade">' . $count . '.</span> ' . $studentSubjectListVal['subj_desc'] . ' (' . $studentSubjectListVal['subj_code'] . ')</div>';
					$count++;
				}
			}
			$subjListHTML .= '<div class="subj-list-spacer"></div>';

			$TEMP->set_var(array('subj_list' => $subjListHTML));
			$TEMP->parse('subjectsRow', 'subjects', true);
		}
		
	}
	else {
		$TEMP->set_var(array('subj_list' => ''));
	}

	$TEMP->set_var(array('stud_id'			=> $stud_idPK,
						 'stud_no'			=> $stud_no,
						 'first_name'		=> $first_name,
						 'middle_name'		=> $middle_name,
						 'last_name'		=> $last_name,
						 'course_id'		=> $course_idFK,
						 'course_desc'		=> $course_desc,
						 'dept_desc'		=> $dept_desc,
						 'sem_desc'			=> $semesterLabel['sem_desc'],
						 'sem_code'			=> $semesterLabel['sem_code'],
						 'reg_sub_menu'		=> $pageLib->registrarSubMenu(DIR_IMAGES),
						 'redirect'			=> $REDIRECT,
						 'stud_sem_id'		=> $activeSemesterStud['stud_sem_idPK']
						));
?>